//
//  EditTimeView.m
//  QRMaster
//
//  Created by myApple on 16/5/19.
//  Copyright © 2016年 myApple. All rights reserved.
//

#import "EditStaffTimeView.h"

typedef NS_ENUM(NSInteger,SelectType) {
    SelectTypeRoom = 0,
    SelectTypeFloor,
    SelectTypeBuilding,
};

@interface EditStaffTimeView ()
{
    NSArray * nameArray;
}

@end

@implementation EditStaffTimeView


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        nameArray = @[@"房间",@"楼层",@"楼栋"];
        [self prepareView];
    }
    return self;
}

-(void)prepareView
{
    float x = 0;
    float y = self.frame.size.height - 200;
    float height = 200;
    float width = self.frame.size.width;
    
    UIView * sheetView = [[UIView alloc]initWithFrame:CGRectMake(x, y, width, height)];
    sheetView.backgroundColor = [UIColor whiteColor];
    sheetView.userInteractionEnabled = YES;
    UITapGestureRecognizer * sheetTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickSheet)];
    [sheetView addGestureRecognizer:sheetTap];
    [self addSubview:sheetView];
    
    y = 0;
    height = 30;
    UIView * communtiyView = [[UIView alloc]initWithFrame:CGRectMake(x, y, width, height)];
    communtiyView.backgroundColor = UIColorFromRGB(0x7dc234);
    [sheetView addSubview:communtiyView];
    
    y = 5;
    height = 20;
    UILabel * communityLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    communityLabel.text = [QRSingleton sharedQRSingleton].communityName;
    communityLabel.font = [UIFont systemFontOfSize:16.0];
    communityLabel.textAlignment = NSTextAlignmentCenter;
    communityLabel.textColor = [UIColor whiteColor];
    [communtiyView addSubview:communityLabel];
    
    float imageWidth = 39;
    float xOffSet = (UI_SCREEN_WIDTH - 39 * 3)/4.0;
    for (NSInteger i = 0; i < 3; i ++) {
        x = xOffSet * (i + 1) + imageWidth * i;
        y = 40;
        width = imageWidth;
        height = imageWidth;
        UIImageView * allImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, width, height)];
        allImageView.image = [UIImage imageNamed:@"assignTimeImage"];
        allImageView.userInteractionEnabled = YES;
        UITapGestureRecognizer * tapImage = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectStye:)];
        [allImageView addGestureRecognizer:tapImage];
        allImageView.tag = SelectTypeRoom + i;
        [sheetView addSubview:allImageView];
        
        y += 5 + height;
        UILabel * allImageLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y,width, height)];
        allImageLabel.font = [UIFont systemFontOfSize:15.0];
        allImageLabel.textAlignment = NSTextAlignmentCenter;
        allImageLabel.text = nameArray[i];
        [sheetView addSubview:allImageLabel];
    }
}

#pragma mark ---------选择楼栋，楼层，房间
-(void)selectStye:(UITapGestureRecognizer *)tap
{
    if (_delegate && [_delegate respondsToSelector:@selector(EditStaffTimeView:)]) {
        [_delegate EditStaffTimeView:tap.view.tag];
    }
}

-(void)clickSheet
{
    return ;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
